//
//  HsMarketStyleChangeSureView.m
//  TestIos
//
//  Created by hs on 2020/10/21.
//  Copyright © 2020 Liyadong. All rights reserved.
//

#import "HsMarketStyleChangeSureView.h"
#import "Masonry.h"


#define sure_content_W  270
#define sure_content_H  375


#define sure_btn_left_margin 16

#define sure_btn_bottom_margin 24

#define sure_btn_H  44

#define top_round_view_H    100

#define top_round_conten_image_H    35


#define top_close_btn_H     30

#define sure_view_layer_corners 4


@interface HsMarketStyleChangeSureView ()

/** close btn */
@property (nonatomic, strong) UIButton *closeBtn;

/** sure btn */
@property (nonatomic, strong) UIButton *sureBtn;

/** 白色模式承载图 */
@property (nonatomic, strong) UIView *whiteContenView;

/** 黑色模式承载图 */
@property (nonatomic, strong) UIView *blackContenView;

/** 智能模式承载图 */
@property (nonatomic, strong) UIView *aiContenView;


@end


@implementation HsMarketStyleChangeSureView

#pragma mark - initfunction
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
       
        self.layer.cornerRadius = sure_view_layer_corners;
        self.layer.masksToBounds = YES;
        
        [self addSubview:self.whiteContenView];
        
        [self.whiteContenView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_equalTo(0);
        }];
        
        [self addSubview:self.blackContenView];

        [self.blackContenView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_equalTo(0);
        }];


        [self addSubview:self.aiContenView];

        [self.aiContenView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.top.mas_equalTo(50);
        }];
        
        
        [self addSubview:self.closeBtn];
        [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(top_round_view_H / 2);
            make.right.mas_equalTo(0);
            make.height.width.mas_equalTo(top_close_btn_H);
        }];
        
        [self addSubview:self.sureBtn];
        [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(sure_btn_left_margin);
            make.right.mas_equalTo(-sure_btn_left_margin);
            make.height.mas_equalTo(sure_btn_H);
            make.bottom.mas_equalTo(-sure_btn_bottom_margin);
        }];
        
        
    }
    return self;
}


- (HsMarketStyleChangeSureView *)createSureViewWithStyle:(HsMarketSureViewStyle)sureStyle {
    
    HsMarketStyleChangeSureView *sureView = [[HsMarketStyleChangeSureView alloc] initWithFrame:CGRectMake(0, 0, sure_content_W, sure_content_H)];
    
    if (sureStyle == HsMarketSureViewStyleWhite) {
        sureView.whiteContenView.hidden = NO;
        sureView.blackContenView.hidden = YES;
        sureView.aiContenView.hidden = YES;

    } else if(sureStyle == HsMarketSureViewStyleBlack){
        sureView.whiteContenView.hidden = YES;
        sureView.blackContenView.hidden = NO;
        sureView.aiContenView.hidden = YES;
    } else {
        sureView.whiteContenView.hidden = YES;
        sureView.blackContenView.hidden = YES;
        sureView.aiContenView.hidden = NO;
    }
    
    
    if (sureStyle == HsMarketSureViewStyleAi) {
        
        sureView.sureBtn.layer.cornerRadius = 0;
        [sureView.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.height.mas_equalTo(sure_btn_H);
        }];
        
         
        
        
    } else {
        sureView.sureBtn.layer.cornerRadius = sure_view_layer_corners;
        [sureView.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(sure_btn_left_margin);
            make.right.mas_equalTo(-sure_btn_left_margin);
            make.height.mas_equalTo(sure_btn_H);
            make.bottom.mas_equalTo(-sure_btn_bottom_margin);
        }];
        
         
    }
    
        
    

    return sureView;
}





#pragma mark - lazyload
- (UIButton *)closeBtn {
    if (!_closeBtn) {
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setImage:[UIImage imageNamed:@"lczq_market_style_close"] forState:UIControlStateNormal];
        _closeBtn.layer.cornerRadius = sure_view_layer_corners;
        _closeBtn.layer.masksToBounds = YES;
        [_closeBtn addTarget:self action:@selector(handleClose:) forControlEvents:UIControlEventTouchUpInside];
        _closeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _closeBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
     }
    return _closeBtn;
}

- (UIButton *)sureBtn {
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _sureBtn.backgroundColor = [UIColor colorWithHexString:@"#EF4034"];
        [_sureBtn setTitle:@"确认修改" forState:UIControlStateNormal];
        UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
        _sureBtn.titleLabel.font = font;
    
        _sureBtn.layer.cornerRadius = sure_view_layer_corners;
        _sureBtn.layer.masksToBounds = YES;
        
        [_sureBtn addTarget:self action:@selector(handleSure:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureBtn;
}

- (UIView *)blackContenView {
    if (!_blackContenView) {
        _blackContenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, sure_content_W, sure_content_H)];
        _blackContenView.backgroundColor = [UIColor clearColor];
        UIImageView *topBackImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lczq_market_style_black_bview"]];
        [_blackContenView addSubview:topBackImageV];
        [topBackImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.top.mas_equalTo(top_round_view_H / 2);
        }];
        
        UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectZero];
        labelOne.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
        labelOne.text = @"经典版行情";
        labelOne.textAlignment = NSTextAlignmentCenter;
        UIFont *font = [UIFont systemFontOfSize:30 weight:UIFontWeightMedium];
        labelOne.font = font;
        [topBackImageV addSubview:labelOne];
        [labelOne mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(67);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(42);
        }];
        
        UILabel *labelTwo = [[UILabel alloc] initWithFrame:CGRectZero];
        labelTwo.textColor = [UIColor colorWithHexString:@"#FFD8A6"];
        labelTwo.text = @"最初经典依旧在";
        labelTwo.textAlignment = NSTextAlignmentCenter;
        UIFont *font2 = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
        labelTwo.font = font2;
        [topBackImageV addSubview:labelTwo];
        [labelTwo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(labelOne.mas_bottom).mas_offset(12);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(23);
        }];
        

        UIView *topRoundView = [[UIView alloc] initWithFrame:CGRectZero];
        [_blackContenView addSubview:topRoundView];
        topRoundView.layer.cornerRadius = top_round_view_H / 2;
        topRoundView.backgroundColor = [UIColor colorWithHexString:@"#232425"];
        topRoundView.layer.masksToBounds = YES;
        [topRoundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(_blackContenView.mas_centerX);
            make.width.height.mas_equalTo(top_round_view_H);
            make.top.mas_equalTo(0);
        }];

        UIImageView *topImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lczq_market_style_black_moon"]];
        [topRoundView addSubview:topImageV];
        [topImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(topRoundView.mas_centerX);
            make.centerY.mas_equalTo(topRoundView.mas_centerY);
            make.width.height.mas_equalTo(top_round_conten_image_H);
        }];
        
    }
    return _blackContenView;
}

- (UIView *)whiteContenView {
    if (!_whiteContenView) {
        _whiteContenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, sure_content_W, sure_content_H)];
        _whiteContenView.backgroundColor = [UIColor clearColor];
        
        UIImageView *topBackImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lczq_market_style_white_bview"]];
//        topBackImageV.layer.masksToBounds =
        [_whiteContenView addSubview:topBackImageV];
        [topBackImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.top.mas_equalTo(50);
        }];
        
        UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectZero];
        labelOne.textColor = [UIColor colorWithHexString:@"#2A2B30"];
        labelOne.text = @"白色版行情";
        labelOne.textAlignment = NSTextAlignmentCenter;
        UIFont *font = [UIFont systemFontOfSize:30 weight:UIFontWeightMedium];
        labelOne.font = font;
        [topBackImageV addSubview:labelOne];
        [labelOne mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(67);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(42);
        }];
        
        UILabel *labelTwo = [[UILabel alloc] initWithFrame:CGRectZero];
        labelTwo.textColor = [UIColor colorWithHexString:@"#2A2B30"];
        labelTwo.text = @"更简洁 更清晰 更好用";
        labelTwo.textAlignment = NSTextAlignmentCenter;
        UIFont *font2 = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
        labelTwo.font = font2;
        [topBackImageV addSubview:labelTwo];
        [labelTwo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(labelOne.mas_bottom).mas_offset(12);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(23);
        }];
        
        UIView *topRoundView = [[UIView alloc] initWithFrame:CGRectZero];
        [_whiteContenView addSubview:topRoundView];
        topRoundView.layer.cornerRadius = top_round_view_H /2;
        topRoundView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
        topRoundView.layer.masksToBounds = YES;
        [topRoundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(_whiteContenView.mas_centerX);
            make.width.height.mas_equalTo(top_round_view_H);
            make.top.mas_equalTo(0);
        }];
        
        UIImageView *topImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lczq_market_style_white_sun"]];
        [topRoundView addSubview:topImageV];
        [topImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(topRoundView.mas_centerX);
            make.centerY.mas_equalTo(topRoundView.mas_centerY);
            make.width.height.mas_equalTo(top_round_conten_image_H);
        }];
        
        
    }
    return _whiteContenView;
}



- (UIView *)aiContenView {
    if (!_aiContenView) {
        _aiContenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, sure_content_W, sure_content_H)];
                
        _aiContenView.backgroundColor = [UIColor blueColor];
        UIImageView *topBackImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lczq_market_style_ai_black_bview"]];
//        topBackImageV.layer.masksToBounds =
        [_aiContenView addSubview:topBackImageV];
        [topBackImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.mas_equalTo(0);
            make.height.mas_equalTo(140);
        }];
        
        UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectZero];
        labelOne.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
        labelOne.text = @"经典版行情";
        labelOne.textAlignment = NSTextAlignmentCenter;
        UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
        labelOne.font = font;
        [topBackImageV addSubview:labelOne];
        [labelOne mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(43);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(21);
        }];
        
        UILabel *labelTwo = [[UILabel alloc] initWithFrame:CGRectZero];
        labelTwo.textColor = [UIColor colorWithHexString:@"#FFD8A6"];
        labelTwo.text = @"19:00";
        labelTwo.textAlignment = NSTextAlignmentCenter;
        UIFont *font2 = [UIFont systemFontOfSize:36 weight:UIFontWeightRegular];
        labelTwo.font = font2;
        [topBackImageV addSubview:labelTwo];
        [labelTwo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(labelOne.mas_bottom);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(42);
        }];
        
        
        UIImageView *bottomBackImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lczq_market_style_ai_white_bview"]];
        [_aiContenView addSubview:bottomBackImageV];
        [bottomBackImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(topBackImageV.mas_bottom);
            make.bottom.mas_equalTo(-sure_btn_H);
            make.left.right.mas_equalTo(0);
        }];
        
        
        UILabel *labelOne2 = [[UILabel alloc] initWithFrame:CGRectZero];
        labelOne2.textColor = [UIColor colorWithHexString:@"#2A2B30"];
        labelOne2.text = @"白色版行情";
        labelOne2.textAlignment = NSTextAlignmentCenter;
        UIFont *font3 = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
        labelOne2.font = font3;
        [bottomBackImageV addSubview:labelOne2];
        [labelOne2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(43);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(21);
        }];
        
        UILabel *labelTwo2 = [[UILabel alloc] initWithFrame:CGRectZero];
        labelTwo2.textColor = [UIColor colorWithHexString:@"#2A2B30"];
        labelTwo2.text = @"6:00";
        labelTwo2.textAlignment = NSTextAlignmentCenter;
        UIFont *font4 = [UIFont systemFontOfSize:30 weight:UIFontWeightRegular];
        labelTwo2.font = font4;
        [bottomBackImageV addSubview:labelTwo2];
        [labelTwo2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(labelOne2.mas_bottom);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(42);
        }];
    }
    return _aiContenView;
}



#pragma mark - action
- (void)handleSure:(id)sender {
    if (self.sureCallBack) {
        self.sureCallBack();
    }
    
}
- (void)handleClose:(id)sender {
    if (self.closeCallBack) {
        self.closeCallBack();
    }
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
